package com.atguigu.JVMDay02;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class OOMDemo {
    public static void main(String[] args) {
        ArrayList<Dog> arrayList = new ArrayList<>();
        while(true){
            System.out.println("最大堆大小：Xmx=");
            System.out.println(Runtime.getRuntime().maxMemory() /1024.0/1024+"M");
            System.out.println("剩余堆大小：free mem=");
            System.out.println(Runtime.getRuntime().freeMemory() /1024.0/1024+"M");
            System.out.println("当前堆大小：total mem=");
            System.out.println(Runtime.getRuntime().totalMemory() /1024.0/1024+"M");

            arrayList.add(new Dog());
            //线程睡眠几秒
            try {
                TimeUnit.SECONDS.sleep(1);} catch (InterruptedException e) {throw new RuntimeException(e);}

                       System.gc();
        }
    }
}
class Dog{
    Integer id;
    String dogName;
    byte[] bytes = new byte[1*1024*1024];//1MB
}
